package com.deepakchandwani.main;

import java.io.Serializable;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.deepakchandwani.university.Student;
import com.deepakchandwani.university.Teacher;
import com.deepakchandwani.util.HibernateUtil;

public class TPCCWithUnionTester {

	public static void main(String[] args) {
		Student student = new Student();
		Teacher teacher = new Teacher();

		student.setName("Saurabh");
		student.setYear(2);
		student.setDepartment("CSE");

		teacher.setExperience(4);
		teacher.setName("Priyanka");
		teacher.setSpecialization("Java");
		teacher.setDepartment("CSE");

		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction transaction = session.beginTransaction();
		Serializable id = session.save(student);
		session.save(teacher);
		transaction.commit();

		session = HibernateUtil.getSessionFactory().openSession();
		transaction = session.beginTransaction();
		Student resultStudent = (Student) session.load(Student.class, id);
		transaction.commit();

		System.out.println(student.getName() + ", " + student.getDepartment()
				+ ", " + student.getYear());

	}

}
